package com.lovo.roomProject.updatePwd.dao.impl;

import com.lovo.roomProject.dao.BaseDAO;
import com.lovo.roomProject.pojo.LoginUser;
import com.lovo.roomProject.pojo.SystemDO;
import com.lovo.roomProject.updatePwd.dao.UpdatePwdDAO;

import java.sql.SQLException;

public class UpdatePwdDAOImpl extends BaseDAO implements UpdatePwdDAO {
    @Override
    public void update(LoginUser systemDO) {
        this.getConnection();
        String sql="update t_user set u_user_password=? where u_user_name=?";
        try {
            statement=con.prepareStatement(sql);
            statement.setObject(1,systemDO.getLoginUserPwd());
            statement.setObject(2,systemDO.getLoginUserName());
            statement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            close();
        }

    }

    @Override
    public LoginUser getUserName(String name) {
        this.getConnection();
        String sql="select * from t_user where u_user_name=?";
        LoginUser loginUser=new LoginUser();
        try {
            statement=con.prepareStatement(sql);
            statement.setObject(1,name);
            rs=statement.executeQuery();
            while (rs.next()){
                loginUser.setId(rs.getInt("u_id"));
                loginUser.setLoginUserName(rs.getString("u_user_name"));
                loginUser.setLoginUserPwd(rs.getString("u_user_password"));

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return loginUser;
    }
}
